package com.m3839.sdk.common.util;

import android.app.Activity;

import com.m3839.sdk.common.core.ErrorConstant;

/**
 * @author ChenBaoyang
 * @description: ConditionUtils: SDK内部公共，通用的条件判断
 * @date 2021/12/8 13:51
 */
public class ConditionUtils {

    public static boolean commonCondition(Activity activity, ConditionCallback callback) {
        if(activity == null && callback !=null) {
            callback.callback(ErrorConstant.HYKB_CODE_ACTIVITY_IS_NULL, ErrorConstant.ERR_MSG_SDK_ACTIVITY_IS_NULL);
            return false;
        }

        if (!NetworkUtils.isConnected(activity)) {
            ToastUtil.showToast(activity, ErrorConstant.ERR_MSG_NETWORK_ERROR);
            callback.callback(ErrorConstant.HYKB_CODE_NETWORK_ERROR, ErrorConstant.ERR_MSG_NETWORK_ERROR);
            return false;
        }

        return !FastClickUtils.isFastDoubleClick();
    }

    public interface ConditionCallback {
        /**
         * 公共回调
         * @param code
         * @param message
         */
        void callback(int code, String message);
    }
}
